// ~/server/api/users.ts
import connection from "~/server/mysql";

export default defineEventHandler(async (event) => {
  try {
    const [data] = await connection.query('select id,name,age,create_by,create_time,update_by,update_time from sys_user');
    return {
      code: 200,
      message: 'success',
      data
    }; // 返回查询结果
  } catch (error) {
    console.error('MySQL error: ', error);
    return sendError(event, createError({ statusCode: 500, statusMessage: 'Database error' }));
  }
});